let good_ips = new Map;

let good_cookies = new Set;

/**
 * 
 * @param {String} ip 
 */
function addGoodIp(ip) {
    good_ips.set(ip, Date.now() + 1 * 24 * 60 * 60 * 1000);
    // setTimeout(function deleteIt() {
    //     good_ips.delete(ip);
    // }, 30 * 24 * 60 * 60 * 1000);//30天后重新认证

    "?????数字设成30天的秒居然不行??太大了超出范围了么?"
    "太大的数字会导致溢出，callback被直接执行，所以不能用setTimeout"
}
/**
 * 
 * @param {String} ip 
 */
function isGoodIp(ip) {
    if (good_ips.has(ip)) {
        if (Date.now() <= good_ips.get(ip)) {
            return true;
        } else {
            good_ips.delete(ip);
            return false;
        }
    }
    return false;
}

/**
 * 
 * @param {String} cookie 
 */
function addGoodCookie(cookie) {
    good_cookies.add(cookie);
    //cookie暂时没有过期功能
}



/**
 * 
 * @param {String} cookie 
 */
function isGoodCookie(cookie) {
    return good_cookies.has(cookie);
}

module.exports = {
    isGoodCookie: isGoodCookie,
    isGoodIp: isGoodIp,
    addGoodCookie: addGoodCookie,
    addGoodIp: addGoodIp
}